define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'tongcheng/platform_balance_log/index' + location.search,
                    // add_url: 'tongcheng/platform_balance_log/add',
                    // edit_url: 'tongcheng/platform_balance_log/edit',
                    // del_url: 'tongcheng/platform_balance_log/del',
                    // multi_url: 'tongcheng/platform_balance_log/multi',
                    // import_url: 'tongcheng/platform_balance_log/import',
                    table: 'tongcheng_platform_balance_log',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#balance").text('¥ ' + data.balance.balance);
                $("#total_base_fee").text('¥ ' + data.balance.total_base_fee);
                $("#total_delivery_fee").text('¥ ' + data.balance.total_delivery_fee);
                $("#total_rider_withdraw_hand_fee").text('¥ ' + data.balance.total_rider_withdraw_hand_fee);
                $("#total_rider_withdraw").text('¥ ' + data.balance.total_rider_withdraw);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'zone_id', title: __('Zone_id'), visible: false,},
                        {
                            field: 'zone.name', title: __('Zone.name'), operate: false, formatter: function (value, row, index) {
                                return value + '(' + row.zone_id + ')';
                            }
                        },
                        {field: 'user_id', title: __('User_id'), visible: false},
                        {
                            field: 'user.nickname', title: __('User.nickname'), operate: false, formatter: function (value, row, index) {
                                return value + '(' + row.user_id + ')';
                            }
                        },
                        {field: 'rider_id', title: __('Rider_id'), visible: false},
                        {
                            field: 'rider.real_name', title: __('Rider.real_name'), operate: false, formatter: function (value, row, index) {
                                return value + '(' + row.rider_id + ')';
                            }
                        },
                        {field: 'type', title: __('Type'), searchList: {"INC":__('Inc'),"DEC":__('Dec')}, formatter: Table.api.formatter.label},
                        {field: 'kind', title: __('Kind'), searchList: {"BASE_FEE":__('BASE_FEE'),"DELIVERY":__('DELIVERY'),"RIDER_WITHDRAW_HAND_FEE":__('RIDER_WITHDRAW_HAND_FEE'),"ZONE_WITHDRAW_HAND_FEE":__('ZONE_WITHDRAW_HAND_FEE'),"RIDER_WITHDRAW":__('RIDER_WITHDRAW'),"ZONE_WITHDRAW":__('ZONE_WITHDRAW')}, formatter: Table.api.formatter.label},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'before', title: __('Before'), operate:'BETWEEN'},
                        {field: 'after', title: __('After'), operate:'BETWEEN'},
                        {field: 'changeable_id', title: __('Changeable_id')},
                        // {field: 'changeable_type', title: __('Changeable_type'), operate: 'LIKE'},
                        {field: 'memo', title: __('Memo'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    title: '查看详情',
                                    text: '查看详情',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    extend: 'data-area=\'["80%", "80%"]\'',
                                    url: function (row) {
                                        return row?.changeable_url
                                    },
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
